package com.tarena.bo;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.tarena.util.HbnUtils;
import com.tarena.vo.User;

/**
 * 用户类访问数据库类
 * 
 * @author hfsd0909
 * 
 */
public class UserDao {

	/**
	 * 判断用户是否存在
	 * 
	 * @param user
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public boolean validateUser(User user) {
		Session s = HbnUtils.getSession();
		String hql = "from User u where u.username=? and u.password=? ";
		Query query = s.createQuery(hql);
		query.setParameter(0, user.getUsername());
		query.setParameter(1, user.getPassword());
		List<User> userList = query.list();
		if (userList.size() == 1) {
			return true;
		} else {
			return false;
		}
	}

}